/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminServInfo: {
                housekeepingServs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                servId: '',
                componentShow: 'adminServ',
                housekeepingTypes: [],
                conditions: {
                    repairWay: '',
                    servName: '',
                    hktId: '',
                    state: '2002',
                    createTime: '',
                    shopId:''

                }
            }
        },
        _initMethod: function () {
            $that._listAdminServs(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listHousekeepingTypes(1,50);
            $that._initservSjtmentTimeInfo();
            vc.emit('adminShop', 'initShop', function (_shop) {
                $that.adminServInfo.conditions.shopId = _shop.shopId;
                $that._listAdminServs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
        },
        _initEvent: function () {
            

            vc.on('adminServ', 'listAdminServ', function (_param) {
                $that._listAdminServs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAdminServs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingTypes: function (_page, _rows) {
                var param = {
                    params: {
                            page : _page,
                            row : _rows,
                            typeCd:1001,
                            shopId:vc.getCurrentCommunity().shopId
                        } };

                //发送get请求
                vc.http.apiGet('/housekeepingType.queryHousekeepingType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminServInfo.housekeepingTypes = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listAdminServs: function (_page, _rows) {

                $that.adminServInfo.conditions.page = _page;
                $that.adminServInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminServInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/housekeepingServ.queryAdminServ',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminServInfo.total = _json.total;
                        $that.adminServInfo.records = _json.records;
                        $that.adminServInfo.housekeepingServs = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminServInfo.records,
                            dataCount: $that.adminServInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _initservSjtmentTimeInfo: function () {

                $('.servSjtmentTime').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd hh:ii:ss',
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.servSjtmentTime').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".servSjtmentTime").val();
                        $that.adminServInfo.conditions.createTime = value;
                    });
            },

            _queryAdminServMethod:function(){
                $that._listAdminServs(DEFAULT_PAGE, DEFAULT_ROWS);

            },

            _openDeleteAdminServModel: function (_housekeepingServ) {
                vc.emit('deleteAdminServ', 'openDeleteAdminServModal', _housekeepingServ);
            },
            _viewServDetail: function (_serv) {
                vc.emit('viewQrCode', 'openQrCodeModal', {
                    title: _serv.servName,
                    url: _serv.pageUrl,
                    remark: '手机扫码查看家政服务',
                });
            },
 
            _moreCondition: function () {
                if ($that.adminServInfo.moreCondition) {
                    $that.adminServInfo.moreCondition = false;
                } else {
                    $that.adminServInfo.moreCondition = true;
                }
            }


        }
    });
})(window.vc);
